import Vue from "vue";
import VueRouter from "vue-router";
import Index from "../views/Index.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/reserve",
    name: "reserve",
    component: () => import("../views/Reserve.vue"),
    meta: {
      title: "选择客房",
      hide_header: true,
    },
  },
  {
    path: "/choose",
    name: "choose",
    component: () => import("../views/Choose.vue"),
    meta: {
      title: "预定",
    },
  },
  {
    path: "/text",
    name: "text",
    component: () => import("../views/admin/text/text.vue"),
    meta: {
      title: "测试界面",
      hide_header: true,
      hide_footer: true,
    },
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/Login.vue"),
    meta: {
      title: "计划行程住宿",
      hide_header: true,
      hide_footer: true,
    },
  },
  {
    path: "/guestroom/clubroom/:roomId",
    name: "clubroom",
    component: () => import("../views/ClubRoom.vue"),
  },
  {
    path: "/food",
    name: "food",
    component: () => import("../views/Food.vue"),
    meta: {
      title: "餐饮美食",
    },
  },
  {
    path: "/spa",
    name: "spa",
    component: () => import("../views/Spa.vue"),
    meta: {
      title: "水疗中心",
    },
  },
  {
    path: "/myadmin",
    name: "myadmin",
    component: () => import("../components/User.vue"),
    meta: {
      title: "酒店后台管理",
      hide_header: true,
      hide_footer: true,
    },
    children: [
      {
        path: "order",
        name: "order",
        component: () => import("../views/admin/order/Order.vue"),
        meta: {
          title: "订单管理",
          hide_header: true,
          hide_footer: true,
        },
        children: [
          {
            path: "roomorder",
            name: "roomorder",
            component: () => import("../views/admin/order/RoomOrder.vue"),
            meta: {
              title: "房间订单",
              hide_header: true,
              hide_footer: true,
            },
          },
        ],
      },
      {
        path: "room",
        name: "room",
        component: () => import("../views/admin/room/Room.vue"),
        meta: {
          title: "客房管理",
          hide_header: true,
          hide_footer: true,
        },
      },
      {
        path: "person",
        name: "person",
        component: () => import("../views/admin/person/Person.vue"),
        meta: {
          title: "人员管理",
          hide_header: true,
          hide_footer: true,
        },
      },
    ],
  },
  {
    path: "/admin",
    name: "admin",
    component: () => import("../components/Admin.vue"),
    meta: {
      title: "管理员登录",
      hide_header: true,
      hide_footer: true,
    },
  },
  {
    path: "/wedding",
    name: "wedding",
    component: () => import("../views/WeddingBanquet.vue"),
    meta: {
      title: "婚宴",
    },
  },
  {
    path: "/position",
    name: "position",
    component: () => import("../views/Position.vue"),
    meta: {
      title: "位置",
    },
  },
  {
    path: "/photos-and-videos",
    name: "photos-and-videos",
    component: () => import("../views/PhotosVideos.vue"),
    meta: {
      title: "图片与视频",
    },
  },
  {
    path: "/experience",
    name: "experience",
    component: () => import("../views/Experience.vue"),
    meta: {
      title: "酒店服务与设施",
    },
  },
  {
    path: "/meeting",
    name: "meeting",
    component: () => import("../views/Meeting.vue"),
    meta: {
      title: "会议与活动",
    },
  },
  {
    path: "/",
    name: "home",
    component: Index,
    meta: {
      title: "首页",
    },
  },
  {
    path: "/guestroom",
    name: "guestroom",
    component: () => import("../views/GuestRoom.vue"),
    meta: {
      title: "住宿与客房",
    },
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

//添加路由守卫
router.beforeEach((to, from, next) => {
  console.log("to;", to); // to == 'myadmin'

  document.title = to.meta.title;
  // const loginStatus = localStorage.getItem("loginStatus");

  // if (loginStatus && loginStatus == "1") {
  //   next();
  // }else{
  //   if(to.path != '/admin') {
  //     next('/admin');
  //   }else {
  //     next();
  //   }
  // }
  next();
});

export default router;
